package com.haier.a920changjingyanshidemo.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.haier.a920changjingyanshidemo.R;

/**
 * Created by 01457215 on 2017/8/22.
 */

public class MyDialog extends Dialog {
    private String mSTR;

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public MyDialog(@NonNull final Context context, String s) {
        super(context);
        this.mSTR = s;
        View inflate = getLayoutInflater().inflate(R.layout.dialog_huanyan, null);
        View viewById = inflate.findViewById(R.id.huanyan_goumai);
        ImageView imageView = (ImageView) inflate.findViewById(R.id.icon_iv);

        if (s.equals("0")) {
            imageView.setBackground(getContext().getResources().getDrawable(R.mipmap.rsj_huanyan));
        } else if (s.equals("1")) {
            imageView.setBackground(getContext().getResources().getDrawable(R.mipmap.rsj_huanxin));
        } else if (s.equals("2")) {
            imageView.setBackground(getContext().getResources().getDrawable(R.mipmap.rsj_huanxin));
        }

        viewById.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSTR.equals("0")) {
                    Intent intent = new Intent(context, GetWaterSheBeiJianRSJ_JYActivity.class);
                    context.startActivity(intent);
                } else if (mSTR.equals("1")) {
                    Intent intent = new Intent(context, GetWaterSheBeiJianZYJS_LXActivity.class);
                    context.startActivity(intent);
                } else if (mSTR.equals("2")) {
                    Intent intent = new Intent(context, GetWaterChuFangJSJ_HanXinActivity.class);
                    context.startActivity(intent);
                }
            }
        });


        //售后
        inflate.findViewById(R.id.huanyan_shouhou).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyShouHouDialog myShouHouDialog = new MyShouHouDialog(context);
                myShouHouDialog.show();
            }
        });
        requestWindowFeature(Window.FEATURE_NO_TITLE);//这句话，就是决定上面的那个黑框，也就是dialog的title。
        super.setContentView(inflate);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams p = dialogWindow.getAttributes();
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        getWindow().setAttributes(p);
        p.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        p.width = (int) (d.getWidth() * 0.8);
        p.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(p);
    }
}
